<?php
namespace Admin\Model;
use Think\Model;

class ProductGroupModel extends Model {
    
    protected $_validate = array(
        array('name', 'require', '名称不能为空', self::EXISTS_VALIDATE, 'regex', self::MODEL_BOTH),
        array('name', '1,50', '名称不能超过50个字符', self::VALUE_VALIDATE , 'length', self::MODEL_BOTH),
        array('group', 'checkGroup', '类型有误', self::MUST_VALIDATE, 'callback', self::MODEL_BOTH)
    );
    
    protected $_auto = array(
        array('create_time', NOW_TIME, self::MODEL_INSERT),
        array('update_time', NOW_TIME, self::MODEL_BOTH)
    );
    
    protected function checkGroup($var){
        if (empty($var)) {
            return false;
        }
        
        return getGroups($var) ? true : false;
    }
}